<?php


namespace ke\web;


use Swoole\WebSocket\Server;

class WebSyncRefresh
{
    private $server;

    private $list = [];

    public function __construct()
    {
    }


    public function boot()
    {
        echo 'WebSyncRefresh start' . PHP_EOL;
        $this->server = new Server('0.0.0.0', 9190);
        $this->server->on('open', [$this, 'open']);
        $this->server->on('message', [$this, 'response']);
        $this->server->on('close', [$this, 'close']);
        $this->server->start();
    }


    public function open(Server $server, $request)
    {
        echo 'WebSyncRefresh connect:' . $request->fd . PHP_EOL;
    }


    public function response(Server $server, $frame)
    {
        echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        $server->push($frame->fd, "this is server");
    }


    public function close()
    {
        echo 'WebSyncRefresh closed' . PHP_EOL;
    }
}
